<?php
global $_W, $_GPC;
$uid = $_GPC['uid'];
$weid = $_W['uniacid'];
if(empty($uid)){
    return $this->getresult(1,'请先登录',array('code'=>3001,'msg'=>'请先登录'));
}
/***校验token开始***/
if($uid){
    $token = $_GPC['token'];
    if (empty($token)) {
        return $this->getresult(1, '请重新登录', ['code' => 4001, 'msg' => '请重新登录']);
    }
    $token_result = $this->checktoken($uid, $token);
    if ($token_result == 1002) {
        return $this->getresult(1, '请重新登录', ['code' => 4002, 'msg' => '请重新登录']);
    } elseif ($token_result == 1003) {
        return $this->getresult(1, '请重新登录', ['code' => 4003, 'msg' => '请重新登录']);
    }elseif ($token_result == 1001) {
        //  更新token
        pdo_update($this->t_user_token,array('createtime'=>time()),array('uid' => $uid, 'token' => $token, 'weid' => $_W['uniacid']));
    }
}
/***校验token结束***/
$params = [':weid' => $weid, ':uid' => $uid, ':is_delete' => 1];
$pList = pdo_fetchall("select fr.id,l.id as lid,su.name as subjectname,l.title from " . tablename('goouc_class_practice_false_record') . " fr LEFT JOIN " . tablename('goouc_class_lesson') . " l ON fr.lessonid = l.id LEFT JOIN " . tablename('goouc_class_subject') . " su ON l.subjectid = su.id" . "  where fr.weid = :weid AND fr.uid = :uid AND fr.is_delete = :is_delete ", $params);
$practiceList = [];
foreach ($pList as $k => $v) {
    $practiceList[$v['lid']] = [
        'subjectname' => $v['subjectname'],
        'title' => $v['title'],
        'lid' => $v['lid']
    ];
}
//统计学员总的错题数
$tparams = array(':weid' => $weid, ':uid' => $uid, ':is_delete' => 1);
$totalNum = pdo_fetchcolumn("select count(*) as total  from " . tablename('goouc_class_practice_false_record') . "  where weid = :weid AND uid = :uid AND is_delete = :is_delete", $tparams);
$data = [
    'totalNum' => $totalNum,
    'list' => $practiceList
];
return $this->getresult(0, '错题本数据', ['code'=>200,'falselist'=>$data]);